<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Index extends AdminTwoController {

	function __construct() {
		parent::__construct();
		$this -> sidebar = "Index";
		$this->load ->library('ProjectService/data_service');
		$this -> load -> model("Audit_model");
		
	}

	function Index() {	
		$this->load->view('admin/index');
	}
	function desktop(){
		$role=explode(',', getSess()['sub_role_id']);
		array_push($role, getSess()['role_id']);

		$data['can_audit']=false;$data['is_teacher']=false;
		if(in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role) && in_array(WebRole::BranchManage[XPHEnum::Value], $role)){
			$connar['where']='1=1';
			$data['can_audit']=true;
		}else if(in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role)){//科研处职员
			$connar['where']=$this->sqlEscape('node=?? ',array(AuditNode::Second[XPHEnum::Value]));
			$data['can_audit']=true;
		}else if(in_array(WebRole::BranchManage[XPHEnum::Value], $role)){//分院管理员
			$connar['where']=$this->sqlEscape('node=?? and dept_name=??',array(AuditNode::First[XPHEnum::Value],getSess()['dept_name']));
			$data['can_audit']=true;
		}elseif(in_array(WebRole::Teacher[XPHEnum::Value], $role)){
			$connar['where']=$this->sqlEscape('admin_id=?? ',array(getSess()['id']));
			$data['is_teacher']=true;
			$data['can_audit']=false;
		}else{
			$connar['where']='1<>1';
			$data['can_audit']=false;
		}
		if(in_array(WebRole::Teacher[XPHEnum::Value], $role)){
			$connar['groupby']="type";
			$connar['items']="count(*) count,type";
			$connar['where'].=$this->sqlEscape(" and state=?? and (is_read=0 or is_read is null) and is_del=0",array(AuditState::Refused[XPHEnum::Value]));
			$count=$this->Audit_model->get_list_full($connar);
		}else{
			$connar['items']="count(*) count";
			$connar['where'].=$this->sqlEscape(" and state=?? and is_del=0",array(AuditState::UnAudit[XPHEnum::Value]));
			$count=$this->Audit_model->get_single_full($connar);
		}

		if(in_array(WebRole::Teacher[XPHEnum::Value], $role)){
			foreach ($count as $k => $v) {
				$data['count'][$k]['count']=$v['count'];
				$data['count'][$k]['type']=(new ResultsType)->show($v['type']);

				switch ($v['type']) {
					case ResultsType::First[XPHEnum::Value]:					
						$data['count'][$k]['href']="Admin/Paper/index";				
						$data['count'][$k]['title']= ResultsType::First[XPHEnum::Caption];
						break;

					case ResultsType::Second[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Monograph/index";
						$data['count'][$k]['title']= ResultsType::Second[XPHEnum::Caption];
						break;
					case ResultsType::Third[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Patent/index";
						$data['count'][$k]['title']= ResultsType::Third[XPHEnum::Caption];
						break;
					case ResultsType::Fourth[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Awards/index";
						$data['count'][$k]['title']= ResultsType::Fourth[XPHEnum::Caption];
						break;
					case ResultsType::Fifth[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Research/index";
						$data['count'][$k]['title']= ResultsType::Fifth[XPHEnum::Caption];
						break;
					case ResultsType::Sixth[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Technical/index";
						$data['count'][$k]['title']= ResultsType::Sixth[XPHEnum::Caption];
						break;
					case ResultsType::Seventh[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Portrait/index";
						$data['count'][$k]['title']= ResultsType::Seventh[XPHEnum::Caption];
						break;
					case ResultsType::Eighth[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Transverse/index";
						$data['count'][$k]['title']= ResultsType::Eighth[XPHEnum::Caption];
						break;
					case ResultsType::Ninth[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Science/index";
						$data['count'][$k]['title']= ResultsType::Ninth[XPHEnum::Caption];
						break;
					case ResultsType::Tenth[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Communication/index";
						$data['count'][$k]['title']= ResultsType::Tenth[XPHEnum::Caption];
						break;
					case ResultsType::Eleventh[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Academic/index";
						$data['count'][$k]['title']= ResultsType::Eleventh[XPHEnum::Caption];
						break;
					case ResultsType::Twelfth[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Academia/index";
						$data['count'][$k]['title']= ResultsType::Twelfth[XPHEnum::Caption];
						break;
					case ResultsType::Thirteen[XPHEnum::Value]:
						$data['count'][$k]['href']="Admin/Subjectplatform/index";
						$data['count'][$k]['title']= ResultsType::Thirteen[XPHEnum::Caption];
						break;				
				}
			}
			if(!isset($data['count'])){
				$data['count']=array();
			}
		}else{
			$data['count']=$count['count'];
		}
		$this->load->view('admin/desktop',$data);
	}
	

}
